import ArithmeticFunctions

amicables [] = []
amicables (x:xs)
          | friend /= 0 = (x,friend):(amicables xs)
          | otherwise = amicables xs
            where friend = getAmicable x

getAmicable x
           | friend /= x && (sigma1 friend - friend) == x = friend
           | otherwise = 0
             where friend = sigma1 x - x

main = foldr (+) 0 $ map fst (amicables [2..10000])


